package com.gxa.meiye.admin.platform.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxa.meiye.admin.platform.mapper.AdvertisementMapper;
import com.gxa.meiye.admin.platform.pojo.vo.*;
import com.gxa.meiye.admin.platform.service.AdvertisementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AdvertisementServiceImpl extends ServiceImpl<AdvertisementMapper, AdvertisementVo> implements AdvertisementService {


    @Autowired
    private AdvertisementMapper advertisementMapper;

    @Override
    public List<AdvertVo> selectAdvertList() {
        List<AdvertVo> advertVo = advertisementMapper.selectAdvertList();
        return advertVo;
    }

    @Override
    public List<SlideshowVo> selectSlideshowList() {
        List<SlideshowVo> slideshowVos = advertisementMapper.selectSlideshowList();
        return slideshowVos;
    }

    @Override
    public Integer addSlideshow(AdvertisementVo advertisementVo) {
        int insert = advertisementMapper.insert(advertisementVo);
        return insert;
    }

    @Override
    public void updateStatus(UpdateStatusVo statusVo) {
        LambdaUpdateWrapper<AdvertisementVo> userVoLambdaUpdateWrapper = Wrappers.lambdaUpdate();
        userVoLambdaUpdateWrapper.eq(AdvertisementVo::getId,statusVo.getId());
        if(statusVo.getStatus()!=0) {
            userVoLambdaUpdateWrapper.set(AdvertisementVo::getStatus, 0);
        }else {
            userVoLambdaUpdateWrapper.set(AdvertisementVo::getStatus, 1);
        }
        advertisementMapper.update(null,userVoLambdaUpdateWrapper);
    }

    @Override
    public List<AdvertisementVo> selectSlideshows(SelectVo selectVo) {
        LambdaQueryWrapper<AdvertisementVo> userVoLambdaQueryWrapper = Wrappers.lambdaQuery();
        userVoLambdaQueryWrapper.like(AdvertisementVo::getTitle,"%"+selectVo.getTitle()+"%")
                .eq(AdvertisementVo::getStatus,selectVo.getStatus());
        List<AdvertisementVo> advertisementVos = advertisementMapper.selectList(userVoLambdaQueryWrapper);
        return advertisementVos;
    }

    @Override
    public List<AdvertisementVo> selectSlides(SelectVo selectVo) {
        LambdaQueryWrapper<AdvertisementVo> userVoLambdaQueryWrapper = Wrappers.lambdaQuery();
        userVoLambdaQueryWrapper.like(AdvertisementVo::getTitle,"%"+selectVo.getTitle()+"%");
        List<AdvertisementVo> advertisementVos = advertisementMapper.selectList(userVoLambdaQueryWrapper);
        return advertisementVos;
    }

    @Override
    public AdvertisementVo selectById(Integer id) {
        AdvertisementVo advertisementVo = advertisementMapper.selectById(id);
        return advertisementVo;
    }

    @Override
    public void updateAdvertisement(AdvertisementVo advertisementVo) {
        advertisementMapper.updateById(advertisementVo);
    }

    @Override
    public void del(Integer id) {
        advertisementMapper.deleteById(id);
    }
}
